package com.ruoyi.api.kehu;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.JiajiaWorkerInterest;
import com.ruoyi.system.service.IJiajiaWorkerInterestService;
import com.ruoyi.system.utils.TokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 社工关注Controller
 * 
 * @author ruoyi
 * @date 2025-04-15
 */
@Controller
@RequestMapping("/api/worker/interest")
public class ApiJiajiaWorkerInterestController
{
    private String prefix = "system/interest";

    @Autowired
    private IJiajiaWorkerInterestService jiajiaWorkerInterestService;

    @GetMapping()
    public String interest()
    {
        return prefix + "/interest";
    }

    /**
     * 查询社工关注列表
     */
    @PostMapping("/list")
    @ResponseBody
    public AjaxResult list(JiajiaWorkerInterest jiajiaWorkerInterest)
    {
        jiajiaWorkerInterest.setUserId(TokenUtil.getUid());
        List<JiajiaWorkerInterest> list = jiajiaWorkerInterestService.selectJiajiaWorkerInterestList(jiajiaWorkerInterest);
        return AjaxResult.success(list);
    }

    /**
     * 导出社工关注列表
     */
    @Log(title = "社工关注", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaWorkerInterest jiajiaWorkerInterest)
    {
        List<JiajiaWorkerInterest> list = jiajiaWorkerInterestService.selectJiajiaWorkerInterestList(jiajiaWorkerInterest);
        ExcelUtil<JiajiaWorkerInterest> util = new ExcelUtil<JiajiaWorkerInterest>(JiajiaWorkerInterest.class);
        return util.exportExcel(list, "社工关注数据");
    }

    /**
     * 新增社工关注
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存社工关注
     */
    @Log(title = "社工关注", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaWorkerInterest jiajiaWorkerInterest)
    {
        return AjaxResult.success(jiajiaWorkerInterestService.insertJiajiaWorkerInterest(jiajiaWorkerInterest));
    }

    /**
     * 修改社工关注
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JiajiaWorkerInterest jiajiaWorkerInterest = jiajiaWorkerInterestService.selectJiajiaWorkerInterestById(id);
        mmap.put("jiajiaWorkerInterest", jiajiaWorkerInterest);
        return prefix + "/edit";
    }

    /**
     * 修改保存社工关注
     */
    @Log(title = "社工关注", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaWorkerInterest jiajiaWorkerInterest)
    {
        return AjaxResult.success(jiajiaWorkerInterestService.updateJiajiaWorkerInterest(jiajiaWorkerInterest));
    }

    /**
     * 删除社工关注
     */
    @Log(title = "社工关注", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return AjaxResult.success(jiajiaWorkerInterestService.deleteJiajiaWorkerInterestByIds(ids));
    }


    /**
     * 取消关注
     */
    @Log(title = "社工关注", businessType = BusinessType.DELETE)
    @PostMapping( "/delete")
    @ResponseBody
    public AjaxResult delete(JiajiaWorkerInterest jiajiaWorkerInterest)
    {
        return AjaxResult.success(jiajiaWorkerInterestService.deleteJiajiaWorkerInterest(jiajiaWorkerInterest));
    }

}
